home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / debug / Panel.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  5.4 KB  |  206 lines

  1. package com.google.analytics.debug
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.Graphics;
  5.    import flash.display.Shape;
  6.    import flash.display.Sprite;
  7.    import flash.events.MouseEvent;
  8.    
  9.    public class Panel extends UISprite
  10.    {
  11.        
  12.       
  13.       private var _savedH:uint;
  14.       
  15.       private var _data:UISprite;
  16.       
  17.       private var _mask:Sprite;
  18.       
  19.       private var _background:Shape;
  20.       
  21.       private var _savedW:uint;
  22.       
  23.       private var _stickToEdge:Boolean;
  24.       
  25.       private var _border:Shape;
  26.       
  27.       private var _borderColor:uint;
  28.       
  29.       protected var baseAlpha:Number;
  30.       
  31.       private var _backgroundColor:uint;
  32.       
  33.       private var _title:Label;
  34.       
  35.       private var _colapsed:Boolean;
  36.       
  37.       private var _name:String;
  38.       
  39.       public function Panel(name:String, width:uint, height:uint, backgroundColor:uint = 0, borderColor:uint = 0, baseAlpha:Number = 0.3, alignement:Align = null, stickToEdge:Boolean = false)
  40.       {
  41.          super();
  42.          _name = name;
  43.          this.name = name;
  44.          this.mouseEnabled = false;
  45.          _colapsed = false;
  46.          forcedWidth = width;
  47.          forcedHeight = height;
  48.          this.baseAlpha = baseAlpha;
  49.          _background = new Shape();
  50.          _data = new UISprite();
  51.          _data.forcedWidth = width;
  52.          _data.forcedHeight = height;
  53.          _data.mouseEnabled = false;
  54.          _title = new Label(name,"uiLabel",16777215,Align.topLeft,stickToEdge);
  55.          _title.buttonMode = true;
  56.          _title.margin.top = 0.6;
  57.          _title.margin.left = 0.6;
  58.          _title.addEventListener(MouseEvent.CLICK,onToggle);
  59.          _title.mouseChildren = false;
  60.          _border = new Shape();
  61.          _mask = new Sprite();
  62.          _mask.useHandCursor = false;
  63.          _mask.mouseEnabled = false;
  64.          _mask.mouseChildren = false;
  65.          if(alignement == null)
  66.          {
  67.             alignement = Align.none;
  68.          }
  69.          this.alignement = alignement;
  70.          this.stickToEdge = stickToEdge;
  71.          if(backgroundColor == 0)
  72.          {
  73.             backgroundColor = uint(Style.backgroundColor);
  74.          }
  75.          _backgroundColor = backgroundColor;
  76.          if(borderColor == 0)
  77.          {
  78.             borderColor = uint(Style.borderColor);
  79.          }
  80.          _borderColor = borderColor;
  81.       }
  82.       
  83.       public function get stickToEdge() : Boolean
  84.       {
  85.          return _stickToEdge;
  86.       }
  87.       
  88.       public function onToggle(event:MouseEvent = null) : void
  89.       {
  90.          if(_colapsed)
  91.          {
  92.             _data.visible = true;
  93.          }
  94.          else
  95.          {
  96.             _data.visible = false;
  97.          }
  98.          _colapsed = !_colapsed;
  99.          _update();
  100.          resize();
  101.       }
  102.       
  103.       public function set stickToEdge(value:Boolean) : void
  104.       {
  105.          _stickToEdge = value;
  106.          _title.stickToEdge = value;
  107.       }
  108.       
  109.       override protected function dispose() : void
  110.       {
  111.          _title.removeEventListener(MouseEvent.CLICK,onToggle);
  112.          super.dispose();
  113.       }
  114.       
  115.       private function _draw() : void
  116.       {
  117.          var W:uint = 0;
  118.          var H:uint = 0;
  119.          if(Boolean(_savedW) && Boolean(_savedH))
  120.          {
  121.             forcedWidth = _savedW;
  122.             forcedHeight = _savedH;
  123.          }
  124.          if(!_colapsed)
  125.          {
  126.             W = forcedWidth;
  127.             H = forcedHeight;
  128.          }
  129.          else
  130.          {
  131.             W = _title.width;
  132.             H = _title.height;
  133.             _savedW = forcedWidth;
  134.             _savedH = forcedHeight;
  135.             forcedWidth = W;
  136.             forcedHeight = H;
  137.          }
  138.          var g0:Graphics = _background.graphics;
  139.          g0.clear();
  140.          g0.beginFill(_backgroundColor);
  141.          Background.drawRounded(this,g0,W,H);
  142.          g0.endFill();
  143.          var g01:Graphics = _data.graphics;
  144.          g01.clear();
  145.          g01.beginFill(_backgroundColor,0);
  146.          Background.drawRounded(this,g01,W,H);
  147.          g01.endFill();
  148.          var g1:Graphics = _border.graphics;
  149.          g1.clear();
  150.          g1.lineStyle(0.1,_borderColor);
  151.          Background.drawRounded(this,g1,W,H);
  152.          g1.endFill();
  153.          var g2:Graphics = _mask.graphics;
  154.          g2.clear();
  155.          g2.beginFill(_backgroundColor);
  156.          Background.drawRounded(this,g2,W + 1,H + 1);
  157.          g2.endFill();
  158.       }
  159.       
  160.       public function get title() : String
  161.       {
  162.          return _title.text;
  163.       }
  164.       
  165.       private function _update() : void
  166.       {
  167.          _draw();
  168.          if(baseAlpha < 1)
  169.          {
  170.             _background.alpha = baseAlpha;
  171.             _border.alpha = baseAlpha;
  172.          }
  173.       }
  174.       
  175.       public function addData(child:DisplayObject) : void
  176.       {
  177.          _data.addChild(child);
  178.       }
  179.       
  180.       override protected function layout() : void
  181.       {
  182.          _update();
  183.          addChild(_background);
  184.          addChild(_data);
  185.          addChild(_title);
  186.          addChild(_border);
  187.          addChild(_mask);
  188.          mask = _mask;
  189.       }
  190.       
  191.       public function set title(value:String) : void
  192.       {
  193.          _title.text = value;
  194.       }
  195.       
  196.       public function close() : void
  197.       {
  198.          dispose();
  199.          if(parent != null)
  200.          {
  201.             parent.removeChild(this);
  202.          }
  203.       }
  204.    }
  205. }
  206.